﻿@model AntUnion.FrameWork.Model.Models.CrmRemittanceAccount
@{
    ViewData["Title"] = "Create";
    Layout = "~/Areas/Console/Views/Shared/_Layout.cshtml";
}
@section head{
    <script type="text/javascript">
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'table', 'form', 'upload'], function () {
            var $ = layui.$
                , form = layui.form
                , admin = layui.admin
                , upload = layui.upload
                , table = layui.table
                , parentFrameIndex = parent.layer.getFrameIndex(window.name); //获取窗口索引;

            /**多语言初始化 */
            top.SetFormPageLanguage(layui);

            $.getJSON("/Withdraw/GetCurrency", function (result) {
                let plat = result.data;
                plat.forEach(function (v) {
                    $('#currency').append(new Option(v, v));
                });
                $("#currency").val('@Model.Currency');
                layui.form.render("select");
            });

            /* 监听提交 */
            form.on('submit(submit-form)', function (data) {
                if ($("#currency").val() == "") {
                    top.AlertByKey(layui, "enterCurrency", 0);
                    return false;
                }
                if ($("#payee").val() == "") {
                    top.AlertByKey(layui, "enterPayee", 0);
                    return false;
                }
                if ($("#accountNumber").val() == "") {
                    top.AlertByKey(layui, "enterAccountNumber", 0);
                    return false;
                }
                if ($("#bank").val() == "") {
                    top.AlertByKey(layui, "enterBank", 0);
                    return false;
                }
                if ($("#branchname").val() == "") {
                    top.AlertByKey(layui, "enterBranchName", 0);
                    return false;
                }
                if ($("#qrcode").attr('src') == "") {
                    top.AlertByKey(layui, "enterQrcode", 0);
                    return false;
                }
                console.log($('#Id').val())
                $.ajax({
                    type: "POST",
                    url: "/Withdraw/EditRemittanceAccount",
                    data: {
                        id: $('#Id').val(),
                        currency: $("#currency option:selected").val(),
                        payee: $("#payee").val(),
                        accountNumber: $("#accountNumber").val(),
                        bank: $("#bank").val(),
                        branchName: $("#branchName").val(),
                        qrcode: $("#qrcode").attr('src'),
                    }, // 你的formid
                    async: true,
                    error: function (request) {
                        alert("Connection error");
                    },
                    beforeSend: function (xhr) {
                        layui.layer.load();
                    },
                    success: function (data) {
                        var item = eval(data);
                        if (item.code == 0) {
                            /**提示语弹框 */
                            top.ShowMessageByKey(layui, item.msg, 6, 1000, function () {
                                parent.layer.close(parentFrameIndex);
                                parent.location.reload();
                            });
                        } else {
                            /**提示语弹框 */
                            top.ShowMessageByKey(layui, item.msg, 0, 1000, function () {
                                parent.layer.close(parentFrameIndex);
                                parent.location.reload();
                            });
                        }
                        layer.closeAll('loading');
                    }
                });
                return false;
            });

            //拖拽上传
            upload.render({
                elem: '#uploadQrcode,#changeOne'
                , url: '/Base/UploadFile' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
                , done: function (res) {
                    top.ShowMessageByKey(layui, "uploadSuccess", 6, 1000);
                    $('#uploadDemoView').removeClass('layui-hide').find('img').attr('src', res.data.src);
                }
            });

            //复制
            $('#remove').click(function () {
                $('#uploadDemoView').val('').addClass('layui-hide').find('img').attr('src', '');
                //$('#certificate').addClass('').attr('src', '');

            })

            //图片预览事件
            $('#uploadDemoView img').click(function (e) {
                previewImg(this);
                e.stopPropagation()
            });
        });
    </script>
}

    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body" style="padding: 15px;">
                <form class="layui-form" action="" lay-filter="component-form-group">
                    @Html.HiddenFor(m => m.Id)
                    <div class="layui-form-item">
                        <label class="layui-form-label" lay-event="currencytitle" style="width:100px;">收款货币</label>
                        <div class="layui-input-block" style="margin-left:130px;">
                            <select name="currency" id="currency" lay-filter="currency" disabled>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" lay-event="wpayeetitle" style="width:100px;">提现户名</label>
                        <div class="layui-input-block" style="margin-left:130px;">
                            <input type="text" name="payee" id="payee" placeholder="enterPayee" class="layui-input" value="@Model.Payee">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" lay-event="wpayeenumbertitle" style="width:100px;">"></label>
                        <div class="layui-input-block" style="margin-left:130px;">
                            <input type="text" name="accountNumber" id="accountNumber" placeholder="enterPayeenumber" class="layui-input" value="@Model.AccountNumber">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" lay-event="wpayeebanktitle" style="width:100px;">提现银行</label>
                        <div class="layui-input-block" style="margin-left:130px;">
                            <input type="text" name="bank" id="bank" placeholder="enterPayeebank" class="layui-input" value="@Model.Bank">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" lay-event="wbankaddresstitle" style="width:100px;">提现银行地址</label>
                        <div class="layui-input-block" style="margin-left:130px;">
                            <input type="text" name="branchName" id="branchName" placeholder="enterbankaddress" class="layui-input" value="@Model.BranchName">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" id="uploadQrcodeTitle" style="width:100px;" lay-event="wqrcodetitle">提现二维码</label>
                        <div class="layui-upload-drag" id="uploadQrcode">
                            <i class="layui-icon"></i>
                            <div class="@(Model.Qrcode==null?"layui-hide":"")" id="uploadDemoView">
                                <hr>
                                <img src="@Model.Qrcode" style="max-width: 196px" id="qrcode" name="qrcode">
                            </div>
                        </div>
                        <button type="button" class="layui-btn" id="changeOne">换一张</button>
                        <button type="button" class="layui-btn layui-btn-danger" id="remove">移除</button>
                    </div>
                    <div class="layui-form-item layui-layout-admin">
                        <div class="layui-input-block">
                            <div class="layui-footer" style="left: 0;">
                                <button id="submitForm" class="layui-btn" lay-submit lay-filter="submit-form">立即提交</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>